<?PHP
function getSetting($area,$areaType,$property){
	$area     = $GLOBALS['db']->EscapeString($area);
	$areaType = $GLOBALS['db']->EscapeString($areaType);
	$property = $GLOBALS['db']->EscapeString($property);
	return $GLOBALS['db']->ReadField("
				SELECT value FROM {'dbprefix'}settings WHERE role = '".$_SESSION['user']->role->ID."' AND area = '".$area."' AND areaType = '".$areaType."' AND property = '".$property."' UNION
				SELECT value FROM {'dbprefix'}settings WHERE role = '3' AND area = '".$area."' AND areaType = '".$areaType."' AND property = '".$property."'
	");
}
function setSetting($area,$areaType,$property,$value,$role){
	$area     = $GLOBALS['db']->EscapeString($area);
	$areaType = $GLOBALS['db']->EscapeString($areaType);
	$property = $GLOBALS['db']->EscapeString($property);
	$value    = $GLOBALS['db']->EscapeString($value);
	$role     = $GLOBALS['db']->EscapeString($role);
	$allUserData = $GLOBALS['db']->ReadRow("SELECT * FROM  {'dbprefix'}settings WHERE area = '".$area."' AND areaType = '".$areaType."' AND property = '".$property."' AND role = '3'");
	if($GLOBALS['db']->EscapeString($allUserData->value) != $value or $role == 3){
		$exists = $GLOBALS['db']->ReadField("SELECT COUNT(*) FROM {'dbprefix'}settings WHERE area = '".$area."' AND areaType = '".$areaType."' AND property = '".$property."' AND role = '".$role."'") > 0;
		if($exists){
			$res = $GLOBALS['db']->Execute("UPDATE {'dbprefix'}settings SET value = '".$value."' WHERE area = '".$area."' AND areaType = '".$areaType."' AND property = '".$property."' AND role = '".$role."'");
		}
		else{
			$res = $GLOBALS['db']->Execute("INSERT INTO {'dbprefix'}settings (value,area,areaType,property,role,description,type) VALUES ('".$value."', '".$area."', '".$areaType."', '".$property."', '".$role."','".$allUserData->description."','".$allUserData->type."')");
		}
	}
	else{
		$GLOBALS['db']->Execute("DELETE FROM {'dbprefix'}settings WHERE area = '".$area."' AND areaType = '".$areaType."' AND property = '".$property."' AND role = '".$role."'") ;
	}
	return $res;
}
?> 